package top.soulblack.purchasesale.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.soulblack.purchasesale.common.enums.ResultEnum;
import top.soulblack.purchasesale.exception.PurchaseException;
import top.soulblack.purchasesale.mapper.OrderDetailMapper;
import top.soulblack.purchasesale.model.OrderDetail;
import top.soulblack.purchasesale.model.VO.OrderDetailVO;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: 韦溜溜
 * @Description:
 * @Date: Create in 20:05 2019/7/18
 */
@Service
@Slf4j
public class OrderDetailService {

    @Autowired
    private OrderDetailMapper orderDetailMapper;

    public Boolean inserListOrderDetail(List<OrderDetail> orderDetailList ){
        int num = orderDetailMapper.insertOrderDetailList(orderDetailList);
        if(num>=1){
            return true;
        }else {
            log.error("【订单详情】插入失败 orderId={}",orderDetailList.get(0).getOrderId());
            throw new PurchaseException(ResultEnum.ORDERINSERTERROR);
        }
    }

    public List<OrderDetail> selectByOrderId(String orderId){
        List<OrderDetail> orderDetailList = orderDetailMapper.selectByOrderId(orderId);
        if(orderDetailList.size()==0){
            log.error("【订单详情】查询失败 orderId={}",orderId);
            throw new PurchaseException(ResultEnum.ORDERDETAILSELECTERROR);
        }
        return orderDetailList;
    }

    public List<OrderDetailVO> getVOByOrderId(String orderId){
        List<OrderDetailVO> orderDetailVOS = orderDetailMapper.findVOByOrderId(orderId);
        if(orderDetailVOS.size()==0){
            log.error("【订单详情】查询失败 orderId={}",orderId);
            throw new PurchaseException(ResultEnum.ORDERDETAILSELECTERROR);
        }
        return orderDetailVOS;
    }


}
